package my.suveng.suxinnetty;

import my.suveng.suxinnetty.wsserver.Wsserver;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * create at 2018/10/31
 * author: suveng
 * email: suveng@163.com
 * 用于监听springboot启动完成后，在初始化netty
 **/
@Component
public class NettyBooter  implements ApplicationListener<ContextRefreshedEvent> {
    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        if (contextRefreshedEvent.getApplicationContext().getParent()==null){
            try {
                Wsserver.getInstance().start();
            }catch (Exception e){
                System.err.println("netty booter 出错了");
                e.printStackTrace();
            }
        }
    }
}
